<?php
/**
 * Created by PhpStorm.
 * User: huihui
 * Date: 2018/6/29
 * Time: 下午3:43
 */

namespace app\admin\model;


use think\Model;

class Userhis extends Model
{
    protected $auto = ['create_time'];

    public function getCreateTimeAttr($time)
    {
        return $time;
    }

    public function getHis($uid)
    {
        $sql = "select rewards.id,rewards.gid,game.winner,sum(rewards.win) as wint,sum(rewards.lose) as loset,game.end_time from rewards left join game on rewards.gid=game.id where rewards.uid=".$uid." and rewards.status=1  group by rewards.gid";
        $result = $this::query($sql);
        foreach ($result as $k=>$v){
            switch ($v['winner']){
                case 0:
                    $result[$k]['winners'] = '平局';
                    break;
                case 1:
                    $result[$k]['winners'] = '蓝方';
                    break;
                case 2:
                    $result[$k]['winners'] = '红方';
                    break;
            }
        }
        return $result;
    }

    //通过比赛ID和UID获取比赛统计结果 不包含明细
    public function getHisInfo($uid,$gid)
    {
        $sql = "SELECT id,kid as k,
                sum(reward) as r0,
                sum(calToScore(reward,kid,direction,kou)) as r1, 
                sum(calToScore(kill_reward,kid,direction,kou)) as k1, 
                sum(win) as w1,sum(lose) as l1,sum(tax) as t1 FROM `rewards` 
                WHERE status=1 and uid=$uid and gid=$gid 
                group by kid order by kid desc";
        $result = $this::query($sql);
        return $result;
    }



}